﻿using CubicFWNet.Data.Models;
using CubicFWNet.Data.ViewModal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CubicFWNet.Data.SystemManager
{
    public class NewsRepository : RepositoryBase<News>
    {
        public IQueryable<NewsView> GetList()
        {
            //var obj =  dbcontext.News.Join(dbcontext.NewsTypes, a => a.Type, b => b.Id, (a, b) => new { a, b.TypeName }) as IQueryable<News>;
            //return obj;
            var result = from n in dbcontext.News
                         join nt in dbcontext.NewsTypes
                         on n.Type equals nt.Id
                         //join u in dbcontext.Users on tech.UserId equals u.Id
                         //into newpublisher
                         where (nt.Class == 2)
                         select new NewsView
                         {
                             Id = n.Id,
                             Name = n.Name,
                             Introduct = n.Introduct,
                             NewsContent = n.NewsContent,
                             Publisher = n.Publisher,
                             IsLimit = n.IsLimit,
                             UserList = n.UserList,
                             Sort = n.Sort,
                             Status = n.Status,
                             CreatorID = n.CreatorID,
                             CreateTime = n.CreateTime,
                             TypeName = nt.TypeName,
                             //UserName = u.RealName
                         };
            return result;
        }

    }
}
